/*
 *	http://code.google.com/p/velleman-usb-experiment-board-tool/
 *
 *	Header for Library for talking to Velleman(c) 8055 USB Experiment Interface Board
 *	Also known as: VM110, P8055, K8055
 *
 *	Requires -lusb to link work
 *
 *	Ref: http://www.velleman.eu/products/view/?id=351346
 *
 *	$Id: libv8055.h 5 2012-04-08 16:02:33Z cregganna@gmail.com $
 *
 *	Author: Tony.Jewell@Cregganna.Com
 *
 *	License: New BSD:
 *	Copyright (c) 2012, Tony.Jewell@Cregganna.Com
 *	All rights reserved.
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions are
 *	met:
 *
 *	Redistributions of source code must retain the above copyright notice,
 *	this list of conditions and the following disclaimer.
 *	Redistributions in binary form must reproduce the above copyright
 *	notice, this list of conditions and the following disclaimer in the
 *	documentation and/or other materials provided with the distribution.
 *
 *	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 *	IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 *	TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 *	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *	HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *	OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef INCLUDE_LIBV8055_H
#define INCLUDE_LIBV8055_H 1

#include <sys/types.h>

#define	V8055_VENDOR_ID		4303
#define V8055_PRODUCT_ID	21760

/*
 * These are the supported V8055 Properties
 */
enum v8055_property {
	V8055_DIGITAL_INPUTS		= 0x001,
	V8055_BOARD_ADDR		= 0x002,
	V8055_ANALOG_INPUT1		= 0x004,
	V8055_ANALOG_INPUT2		= 0x008,
	V8055_DIGITAL_INPUT1_COUNT	= 0x010,
	V8055_DIGITAL_INPUT2_COUNT	= 0x020,
	V8055_DIGITAL_OUTPUTS		= 0x040,
	V8055_ANALOG_OUTPUT1		= 0x080,
	V8055_ANALOG_OUTPUT2		= 0x100
};

/*
 * These are the supported V8055 Actions
 */
enum v8055_action {
	V8055_DIGITAL_INPUT1_COUNT_RESET	= 0x01,
	V8055_DIGITAL_INPUT2_COUNT_RESET	= 0x02
};

/*
 * Open the device as a v8055
 * @hid_device - The filename of the hid device (See V8055_DEFAULT_DEVICE)
 * @for_writing - Boolean:
 *	0 = not for writing (Read Only)
 *	1 = for writing
 * @return - The v8055 context that should be passed to all subsequent calls
 *	Or NULL if board cannot be opened - inspect errno.
 */
typedef void *v8055;
extern v8055 v8055_open(char *hid_device, int for_writing);

/*
 * Close a device previously opened v8055
 * @board - a board previously opened by v8055_open
 */
extern void v8055_close(v8055 board);

/*
 * Validates that the board is a supported Velleman
 *
 * @board - a board previously opened by v8055_open
 * @return: False(0) if not an appropriate board
 */
extern int v8055_validate(v8055 board);

/*
 * get Board Details
 *
 * @board: A board previously opened by v8055_open
 * @info: Filled with the board info
 * @return: 0 if info filled
 *	-1 Cannot determine board info - inspect errno.
 */
struct v8055_board_info {
	u_int	vendor_id;
	u_int	product_id;
	u_int	version;
	char	name[100];
};
extern int v8055_get_board_info(v8055 board, struct v8055_board_info *info);

/*
 * Read a Value given one of the V8055_value 
 *
 * @board: A board previously opened by v8055_open
 * @property: one of the enumerated v8055_property values to read.
 * @return: The Value
 *	-1 if call failed.
 */
extern int v8055_get_value(v8055 board, enum v8055_property property);

/*
 * Write a Value given one of the V8055_value
 *
 * @board: A board previously opened by v8055_open
 * @property: one of the enumerated v8055_property values to write.
 * @value: the value to write
 * @return: The Value
 *	-1 if call failed.
 */
extern int v8055_put_value(v8055 board, enum v8055_property property, u_int value);

/*
 * Perform one of the v8055_action s
 *
 * @board: A board previously opened by v8055_open
 * @action: one of the enumerated v8055_action actions to perform
 * @return: >=0 if call suceeded
 *	-1 if call failed.
 */
extern int v8055_action(v8055 board, enum v8055_action action);

#endif /* INCLUDE_LIBV8055_H */
